// ----------------------------------------------------------------------------------
// Microsoft Developer & Platform Evangelism
// 
// Copyright (c) Microsoft Corporation. All rights reserved.
// 
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// ----------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
// ----------------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// MenuScreen.cs
//
// XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using GoldDigger.Sprites;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
using TPL.Xna.Common;

namespace GoldDigger.Screens
{
    /// <summary>
    /// Base class for screens that contain a menu of options. The user can
    /// move up and down to select an entry, or cancel to back out of the screen.
    /// </summary>
    internal abstract class MenuScreen : Screen
    {
        protected bool _autoLayoutMenuItems = true;

        /// <summary>
        /// Constructor.
        /// </summary>
        protected MenuScreen()
        {
            TransitionOnTime = TimeSpan.FromSeconds(1.0);
            TransitionOffTime = TimeSpan.FromSeconds(1.0);
        }

        /// <summary>
        /// Position menu item
        /// </summary>
        public override void LoadContent()
        {
            //Everything is ready before start to do layout
            base.LoadContent();

            if (_autoLayoutMenuItems)
            {
                const float top = 200f;
                const float padding = 5f;

                var y = top;
                foreach (var m in Sprites.OfType<MenuEntry>())
                {
                    m.Origin = new Vector2(m.TapArea.Width, m.TapArea.Height) / 2;
                    m.Position = new Vector2(400, y);
                    y += m.TapArea.Bottom + padding;
                }
            }
        }
    }
}